package com.tesco.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tesco.dao.YgShoppingcartDao;
import com.tesco.entity.domin.YgShoppingcart;
import com.tesco.service.YgShoppingcartService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class YgShoppingcartServiceImpl extends ServiceImpl<YgShoppingcartDao, YgShoppingcart> implements YgShoppingcartService {

    @Override
    public void insertShoppingCart(int spid,String username) {
        YgShoppingcart ygShoppingcart = new YgShoppingcart();
        ygShoppingcart.setSpid(spid);
        ygShoppingcart.setUsername(username);
        ygShoppingcart.setCreatedat(new Date());
        ygShoppingcart.setSpnum(1);
        this.save(ygShoppingcart);
    }

    @Override
    public List<YgShoppingcart> shoppingCartList(String username) {
        QueryWrapper<YgShoppingcart> ygShoppingcartQueryWrapper = new QueryWrapper<>();
        ygShoppingcartQueryWrapper.eq(YgShoppingcart.COL_USERNAME,username)
        .orderByDesc(YgShoppingcart.COL_CREATEDAT);
        List<YgShoppingcart> list = this.list(ygShoppingcartQueryWrapper);
        return list;
    }

}

